package com.slimbloody.client;

import com.slimbloody.interfaces.HelloRequest;
import com.slimbloody.interfaces.MyServiceGrpc;
import io.grpc.StatusRuntimeException;
import net.devh.boot.grpc.client.inject.GrpcClient;
import org.springframework.stereotype.Service;

@Service
public class CallService {
  @GrpcClient("myService")
  private MyServiceGrpc.MyServiceBlockingStub myServiceStub;

  public String receiveGreeting(String name) {
    try {
      HelloRequest request = HelloRequest.newBuilder()
        .setName(name)
        .build();
      return myServiceStub.sayHello(request).getMessage();
    } catch (final StatusRuntimeException e) {
      return "FAILED with " + e.getStatus().getCode();
    }
  }
}
